home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig13_05.jar / Ch13 / Fig13_05 / fig13_05.cpp
C/C++ Source or Header  |  1997-11-02  |  526b  |  24 lines

  1. // Fig. 13.5: fig13_05.cpp
  2. // Demonstrating new throwing bad_alloc 
  3. // when memory is not allocated
  4. #include <iostream>
  5. #include <new>
  6.  
  7. int main()
  8. {
  9.    double *ptr[ 10 ];
  10.    
  11.    try {   
  12.       for ( int i = 0; i < 10; i++ ) {
  13.          ptr[ i ] = new double[ 5000000 ];
  14.          cout << "Allocated 5000000 doubles in ptr[ " 
  15.               << i << " ]\n";
  16.       }
  17.    }
  18.    catch ( bad_alloc exception ) {
  19.       cout << "Exception occurred: " 
  20.            << exception.what() << endl;
  21.    }
  22.    
  23.    return 0;
  24. }